package com.yiwich.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.yiwich.model.property.InfluxProperty;
import com.yiwich.utils.InfluxDBConnect;

/**
 * @Author: Muscleape
 * @Date: 2019-09-10
 * @Description:
 */

@Configuration
@Slf4j
public class InfluxDBConfiguration {

    @Autowired
    private InfluxProperty influxProperty;

    @Bean
    public InfluxDBConnect getInfluxDBConnect() {
        InfluxDBConnect influxDB = new InfluxDBConnect(influxProperty.getUser(), influxProperty.getPassword(),
        		influxProperty.getUrl(), influxProperty.getDatabase(), influxProperty.getRetentionPolicy(),
        		influxProperty.getRetentionPolicyTime());

        influxDB.influxDbBuild();

        influxDB.createRetentionPolicy();
        log.info("init influxdb::[{}]", influxProperty);
        return influxDB;
    }
}
